package com.cetc.lambda;

import org.junit.Test;

import java.util.Arrays;
import java.util.function.BiFunction;
import java.util.function.Function;
import java.util.function.Supplier;

/**
 * @Classname LambdaTest04
 * @Description 构造器方法引用和数组方法引用的测试
 * @Date 2023/1/5 10:47
 * @Created by louzhuangxi
 */
public class LambdaTest04 {

    @Test
    public void test01() {
        Supplier<Person> supplier = () -> new Person();
        System.out.println(supplier.get());

        System.out.println("****************************");

        Supplier<Person> supplier1 = Person::new;
        System.out.println(supplier1.get());
    }

    @Test
    public void test02() {
        BiFunction<String, Integer, Person> biFunction = (s1, i) -> new Person("张三", 20);
        Person person = biFunction.apply("12", 15);
        System.out.println(person);

        System.out.println("**************************");

        BiFunction<String, Integer, Person> biFunction1 = Person::new;
        Person person1 = biFunction1.apply("121", 15);
        System.out.println(person1);
    }

    /**
     * 数组引用
     */
    @Test
    public void test03() {
        Function<Integer, int[]> function = i -> new int[i];
        System.out.println(Arrays.toString(function.apply(3)));

        System.out.println("**************************");


        Function<Integer, int[]> function1 = int[]::new;
        System.out.println(Arrays.toString(function1.apply(4)));
    }


}
